package com.zzx.threekingdom.judge;

import com.zzx.threekingdom.card.Card;
import com.zzx.threekingdom.card.KnowhowCard;
import com.zzx.threekingdom.judge.Judge.IAskYesNo;
import com.zzx.threekingdom.judge.Judge.IPassAction;
import com.zzx.threekingdom.judge.Judge.IPassCard;
import com.zzx.threekingdom.model.AbsPlayerModel;
import com.zzx.threekingdom.model.ActionInfo;

public class AskImpeccable extends AskAll 
{
    IAskYesNo mIAsk;
    boolean bResult = false;

    public void beginAsk(AbsPlayerModel from, String action, AbsPlayerModel to, IAskYesNo iAsk)
    {
        actionInfo.clear();
        actionInfo.setActionName(action);
        actionInfo.setFrom(from);
        actionInfo.setTo(to);
        bResult = false;
        mIAsk = iAsk;
        beginAsk(Judge.judge.getLivePmFromeCurrentTurn(), null);
    }
    
    @Override
    public void endAsk()
    {
        actionInfo.clear(); 
        super.endAsk();
        if(mIAsk!=null)
            mIAsk.onResult(bResult);
    }
    
    public void doAsk(final AbsPlayerModel pm, Runnable doneR)
    {
    	IPassAction ipa = new IPassAction() { public void onGotAction(ActionInfo act) {
			pm.onHintText(null);
            pm.setStayWell();
            if(act!=null&&act.getActionName().equals("无懈可击"))
            {
            	pm.drawCard(act.getCard());
                Judge.judge.addLog(pm.getCharacterName() + "打出无懈可击");
                bResult = true;
                AskImpeccable newAskImpeccable = new AskImpeccable();
                
                IAskYesNo r = new IAskYesNo() {
                    public void onResult(boolean yes) {
                        if(yes==true)
                            bResult = !bResult;
                        AskImpeccable.this.endAsk();
                    }
                };
                newAskImpeccable.beginAsk(pm, "无懈可击", null, r);
            }
            else
                goOnAsk();
		}};
        pm.onHintText("是否对" + " " + actionInfo.getHintText() + " " + "使用无懈可击");
        pm.onNeedActionByName("无懈可击", ipa, actionInfo);
    }


}
